package org.nf.web.servlet.resource;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import org.nf.web.servlet.HttpRequestHandler;
import org.nf.web.servlet.ServletApi;

import java.io.IOException;

/**
 * @author wangliang
 * @date 2022/6/14
 * 默认的静态资源处理器，转发给容器的DefaultServlet处理
 */
public class DefaultServletHttpRequestHandler implements HttpRequestHandler {

    private static final String DEFAULT_SERVLET_NAME = "default";

    /**
     * 转发给web容器的默认Servlet处理请求
     */
    @Override
    public void handleRequest(ServletApi servletApi) throws ServletException, IOException {
        //获取ServletContext对象
        ServletContext sc = servletApi.request().getServletContext();
        //根据默认Servlet配置的<servlet-name>来获取
        sc.getNamedDispatcher(DEFAULT_SERVLET_NAME).forward(servletApi.request(), servletApi.response());
    }
}
